package cc.iotkit.data.dao;

import cc.iotkit.data.model.TbAreaMapping;
import cc.iotkit.model.device.DeviceInfoArea;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

public interface AreaMappingRepository extends JpaRepository<TbAreaMapping, Long> {
    /**
     * 查询当前区域下的所有设备
     */
    @Query(value = "select di.id as did,di.device_name as deviceName,di.model as model,di.longitude as longitude," +
            "di.latitude as latitude," +
            "di.state as state,di.online_time as onlineTime,di.offline_time as offlineTime," +
            "a.name as name,a.id as areaId  from  area_mapping am,device_info di ,area a where am.device_id = di.device_id " +
            "and am.area_id = a.id and am.area_id = ?1", nativeQuery = true)
    Page<DeviceInfoArea> findAllByAreaId(Long areaId, Pageable pageable);

    @Query(value = "select * from area_mapping where area_id = ?1 ",nativeQuery = true)
    Page<TbAreaMapping> findAllByAid(String aid, Pageable pageable);
}
